﻿using StudySystem.MainLogic.FormControl;
using StudySystem.MainLogic.Items;
using StudySystem.SQLServer;
using StudySystem.Windows;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace StudySystem
{
    public partial class FormSubject : Form
    {
        public List<ClassSubject> subjects;
        public FormSubject()
        {
            InitializeComponent();
        }
        public FormSubject(List<ClassSubject> subjects)
        {
            InitializeComponent();
            this.subjects = subjects;
        }

        private void FormSubject_FormClosing(object sender, FormClosingEventArgs e)
        {
            FormController.mainForm.Show();
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void btnAddSub_Click(object sender, EventArgs e)
        {
            if(ClassSubject.CheckSubName(txtBoxSubName.Text,subjects))
            {
                subjects = ClassSubject.InsertASubject(txtBoxSubName.Text);
                FormSubControl.RenewSubject(this, subjects);
                DialogResult dr = MessageBox.Show("添加课程成功！");
                if(dr == DialogResult.OK)
                {
                    txtBoxSubName.Text = "";
                }
            }
            else
            {
                MessageBox.Show("添加课程失败，存在同名课程！");
            }
            //this.flpSubject.Controls.Add(new Subject());
        }

        private void subject1_Load(object sender, EventArgs e)
        {

        }

        private void FormSubject_Load(object sender, EventArgs e)
        {
            //Logic.GetSubject();
            FormSubControl.ShowSubjects(this, subjects);
        }

        private void btnQuesSetting_Click(object sender, EventArgs e)
        {
            FormController.SelectQuestionControl(flpSubject,gbSeleQues, btnQuesSetting);
        }

        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            FormController.SetAllSubQuesCount((int)numericUpDown1.Value, flpSubject);
        }

        private void btnSelect_Click(object sender, EventArgs e)
        {
            List<ClassQuestion> questions = FormSubControl.RandomSelectQues(this);
            FormSelectedQues formSeleQues = new FormSelectedQues(questions);
            formSeleQues.Show();
;        }

        private void FormSubject_Activated(object sender, EventArgs e)
        {
            foreach (Subject s in flpSubject.Controls)
            {
                s.RenewSubject();
            }
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            FormSearch fs = new FormSearch();
            fs.Show();
        }
    }
}
